package piwan.gui;

import java.io.File;

import javax.media.opengl.GL;

import com.sun.opengl.util.texture.Texture;
import com.sun.opengl.util.texture.TextureIO;

import piwan.*;

public class HelpOverlay {
	private static final String texFilename = "gfx/cheatsheet.png";
	private GL gl;
	private Texture tex;
	private Vector2 p1 = new Vector2(), p2 = new Vector2();
	private boolean enabled = false;
	
	public HelpOverlay(MainWindow win ) {
		gl = win.getGL();
		
		
		loadTexture();
		int pxwidth = tex.getWidth();
		int pxheight = tex.getHeight();
		
		
		//int pxwidth = 800;
		//int pxheight = 600;
		
		double wwidth = (double)pxwidth/win.getWidth()*2.0;
		double wheight = (double)pxheight/win.getHeight()*2.0;
		
		p1.x = -wwidth/2.0;
		p1.y = -wheight/2.0;
		p2.x = p1.x + wwidth;
		p2.y = p1.y + wheight;
		
	}
	
	public void enable() { enabled = true; }
	public void disable() { enabled = false; }
	
	public void loadTexture() {
		try {
			tex = TextureIO.newTexture(new File(texFilename), false);		
		} catch(Exception e) {
			MainWindow.die(e);
		}
	}
	
	public void render() {
		if(enabled) {
			GameGui.prepareGuiRender(gl, true);
			tex.bind();
			gl.glColor4d(1.0,1.0,1.0,1.0);
			GameGui.renderRect(gl, p1, p2);
		}
	}
	
}
